package com.xq.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xq.response.Result02;
import com.xq.service.TbDepartmentService;
import com.xq.vo.TbDepShowVo;
import com.xq.vo.TbDepVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (TbDepartment)表控制层
 *
 * @author makejava
 * @since 2020-07-25 20:23:48
 */
@RestController
@RequestMapping("tbDepartment")
@Api("部门表")
@CrossOrigin
public class TbDepartmentController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private TbDepartmentService tbDepartmentService;

    @ApiOperation(value = "查询部门信息",notes = "查询部门的所有信息")
    @GetMapping("/findByDepartmentAndCount")
    public Result02 findByDepartmentCount(){
        //tbDepartmentService.list()
        List<TbDepVo> tbDepVo = tbDepartmentService.findByDepartmentCount();
        return Result02.success().data(tbDepVo);
    }

    @ApiOperation(value = "部门表的展示",notes = "有条件的分页展示")
    @GetMapping("findByDepPage/{current}/{size}")
    public Result02 findByDepPage(@PathVariable("current") Integer current,@PathVariable("size") Integer size,@RequestParam(required = false) String name){
        System.out.println("=="+name);
        Page<TbDepShowVo> pageByDep = tbDepartmentService.findPageByDep(current, size, name);
        Map<String,Object> map=new HashMap<>();
        map.put("total",pageByDep.getTotal());
        map.put("size",pageByDep.getSize());
        map.put("current",pageByDep.getCurrent());
        map.put("department",pageByDep.getRecords());
        return Result02.success().data(map);
    }

}